package com.tymoshenko.seabattle.shared.model.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author Yakiv Tymoshenko
 * @since 07.02.13
 */
public class Fleet implements Serializable {

    private Set<Ship> ships;

    public Fleet() {
        final int totalShips = 10;
        ships = new LinkedHashSet<Ship>(totalShips);
    }

    public void  addShip(Ship ship) {
        ships.add(ship);
    }

    public void destroyShip(Ship ship) {
        ships.remove(ship);
    }

    public Ship getShipByDeck(Point deck) {
        for (Ship ship : ships) {
            if (ship.getDecks().contains(deck)) {
                return ship;
            }
        }
        return null;
    }

    public boolean isDestroyed() {
        return ships.isEmpty();
    }

    public Set<Ship> getShips() {
        return new HashSet<Ship>(ships);
    }
}
